package mylib.dir;

/**
 * Created with IntelliJ IDEA.
 * User: 1
 * Date: 02.08.12
 * Time: 21:00
 * To change this template use File | Settings | File Templates.
 */
public class Point3f {
    public double x, y, z;

    public Point3f(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public Point3f add(Point3f other) {
        return new Point3f(x + other.x, y + other.y, z + other.z);
    }

    public Point3f subtract(Point3f other) {
        return new Point3f(x - other.x, y - other.y, z - other.z);
    }

    public double length() {
        return Math.sqrt(x * x + y * y + z * z);
    }

    public double hypot() {
        return x * x + y * y + z * z;
    }

    public Point3f mul(double m) {
        return new Point3f(x * m, y * m, z * m);
    }

    public Point3f divide(double m) {
        return new Point3f(x / m, y / m, z / m);
    }

    public double distance(Point3f other) {
        return Math.sqrt(Math.pow(x - other.x, 2) + Math.pow(y - other.y, 2) +
                Math.pow(z - other.z, 2));
    }

    public Point3f setLength(double d) {
        double f = Math.sqrt(x * x + y * y + z * z);
        return new Point3f(x / f * d, y / f * d, z / f * d);
    }

    public Point3f negate() {
        return new Point3f(-x, -y, -z);
    }

    @Override
    public String toString() {
        return "Point3f{" +
                "x=" + x +
                ", y=" + y +
                ", z=" + z +
                '}';
    }
}